package com.example.experiment2.controller;
import com.example.experiment2.entity.Grade;
import com.example.experiment2.entity.Student;
import com.example.experiment2.service.GradeService;
import com.example.experiment2.service.StudentService;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    private  StudentService studentService;
    private  GradeService gradeService;
    public StudentController(StudentService studentService, GradeService gradeService) {
        this.studentService = studentService;
        this.gradeService = gradeService;
    }
    @GetMapping("/listAll")
    public List<Student> listAll() {
        return studentService.listAll();
    }
    @GetMapping("/getById/{studentId}")
    public Student getById(@PathVariable int studentId) {
        return studentService.getById(studentId);
    }
    @PostMapping("/add")
    public void add(@RequestBody Student student) {
        studentService.add(student);
    }
    @GetMapping("/getGrades/{student_id}")
    public List<Grade> getGradesByStudentId(@PathVariable int student_id) {
       return gradeService.getGradesByStudentId(student_id);
    }
}
